//
//  MyaccountViewController.m
//  Sunexpress
//
//  Created by 筱亮 on 2017/5/9.
//  Copyright © 2017年 曹亮. All rights reserved.
//

#import "MyaccountViewController.h"
#import "MyaccountView.h"
#import "RegisteredViewController.h"
#import "NetWorkingRequest.h"
#import "YCUserDefults.h"
#import "MyaccountModel.h"
#import <SVProgressHUD.h>
@interface MyaccountViewController ()
{
    MyaccountView * view;
}
@end

@implementation MyaccountViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"登录";
    
    
    
    view = [[MyaccountView alloc]initWithFrame:self.view.frame];
    view.backgroundColor = [UIColor colorWithWhite:0.951 alpha:1.000];
    self.view = view;
    
    self.navigationItem.rightBarButtonItem =[[UIBarButtonItem alloc]initWithTitle:@"注册" style:UIBarButtonItemStylePlain target:self action:@selector(zc)];
    
    [view.loginBtn addTarget:self action:@selector(loginBtn) forControlEvents:UIControlEventTouchUpInside];
//    /passport/login?mobile=15122665009&password=123
}
//登录
-(void)loginBtn
{

    [NetWorkingRequest getWithURLString:[NSString stringWithFormat:@"http://daohe.apic.1by1.cc/passport/login?mobile=%@&password=%@",view.pohoneNumber.text,view.password.text] parameters:nil success:^(NSDictionary *data) {
        NSLog(@"+++++%@",data);
        MyaccountModel* mo = [[MyaccountModel alloc]init];
        
        [mo setValuesForKeysWithDictionary:data];


        MyaccountModel_mo * moo = [[MyaccountModel_mo alloc]init];


        
        [moo setValuesForKeysWithDictionary:mo.data];
        
        NSLog(@"========%@",moo.is_locked);
        
        
       if (moo.is_locked==nil) {
            
            [SVProgressHUD showErrorWithStatus:@"登录失败,请注册"];
            
        }
       else if ([moo.is_locked isEqualToString:@"0"]){
            
            [SVProgressHUD showSuccessWithStatus:@"登录成功"];
           
           [YCUserDefults writeUserDataWithKey:moo.token forKey:@"token"];
           
           [self.navigationController popViewControllerAnimated:YES];
        }
     else
     {
         [SVProgressHUD showErrorWithStatus:@"登录失败请检查密码是否正确"];
     }
        
        
        
    } failure:^(NSError *error) {
        
        
    }];
    
    
}

-(void)zc
{
    [self.navigationController pushViewController:[RegisteredViewController new] animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
